package com.kgc.web.listener; /**
 * <h3>项目名称:demo03050</h3>
 * <p>本API描述:${description}</p>
 * <p>@author : AliyZhang</p>
 * <p>@date : 2021-03-08 13:07</p>
 **/

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.text.SimpleDateFormat;
import java.util.Date;

/*监听整个网站应用程序的启动和关闭
* 网站监听器*/
@WebListener
public class MyServletContextListener implements ServletContextListener {

    public MyServletContextListener() {
    }

    @Override
    public void contextInitialized(ServletContextEvent event) {
        /* This method is called when the servlet context is initialized(when the Web application is deployed). */
        /*context，上下文--容器
        监测网站启动起来的时间
         */
        String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        System.out.println("网站监听器，监听到网站启动起来了---"+format);
    }

    @Override
    public void contextDestroyed(ServletContextEvent event) {
        /* This method is called when the servlet Context is undeployed or Application Server shuts down. */
        String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        System.out.println("网站监听器，监听到网站销毁了---"+format);
    }

}
